package com.mrx.compose.demo.router

import androidx.compose.runtime.Composable
import com.mrx.compose.demo.view.ComposeView

/**
 * @author Mr.X
 * @since 2024-05-23 16:57
 **/
class Router {

    private val routerMap: MutableMap<String, ComposeView> = mutableMapOf()

    @Composable
    fun navigate(routerName: String, onNavigation: @Composable (ComposeView) -> Unit) {
        onNavigation(routerMap[routerName]!!)
    }

    fun addRouter(scope: Router.() -> Unit): Router {
        scope()
        return this
    }

    fun String.addRouter(view: ComposeView) {
        routerMap[this] = view
    }

}